<template>
  <div class="container">
    <!-- 顶部区域 -->
    <div class="info-box">
      <van-image
        class="photo"
        width="64"
        height="64"
        round
        fit="cover"
        :src="userInfo.photo"
      />
      <h2 class="name">
        {{ userInfo.name }}
        <br />
        <van-tag type="primary" color="#fff" text-color="#3296fa">
          {{ userInfo.birthday }}
        </van-tag>
      </h2>
    </div>
    <van-row class="user-nav">
      <van-col span="8"
        ><van-icon name="cart-o" color="#1989fa" />
        <br />
        <span>我的作品</span></van-col
      >
      <van-col span="8"
        ><van-icon name="star-o" color="red" />
        <br />
        <span>我的作品</span></van-col
      >
      <van-col span="8"
        ><van-icon name="tosend" color="orange" />
        <br />
        <span>我的作品</span></van-col
      >
    </van-row>
    <van-cell-group class="cell-nav">
      <van-cell icon="edit" to="/edit" title="编辑资料" is-link />
      <van-cell icon="chat-o" to="/student" title="小智同学" is-link />
      <van-cell icon="setting-o" to="/settings" title="系统设置" is-link />
      <van-cell icon="warning-o" title="退出登录" is-link @click="logoutClick"
    /></van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from "./user.js";
import { removeToken } from "@/utils/token.js";
export default {
  name: "user",
  data() {
    return {
      userInfo: {},
    };
  },
  // 生命周期钩子
  created() {
    getUserInfo().then((res) => {
      console.log(res);
      this.userInfo = res.data.data;
      this.$store.commit("setUserInfo", res.data.data);
    });
  },
  methods: {
    logoutClick() {
      this.$dialog
        .confirm({
          title: "温馨提示",
          message: "确认退出本系统？",
        })
        .then(() => {
          removeToken();
          this.userInfo = {};
          this.$router.push({ path: "/home" });
        })
        .catch(() => {
          // on cancel
          console.log("catch");
        });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  .info-box {
    height: 100px;
    display: flex;
    align-items: center;
    background-color: #3296fa;
    .name {
      font-weight: normal;
      padding-left: 20px;
      color: white;
      font-size: 16px;
    }
  }
}
.user-nav {
  font-size: 16px;
  text-align: center;
  .van-icon {
    font-size: 22px;
    padding: 10px 0;
  }
}
.van-image {
  left: 0%;
}
</style>